package com.bestcem.xm.ticket.controller.param.ticket.config;

import com.bestcem.xm.ticket.enums.SurveyTitleTypeEnum;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.util.List;

/**
 * UpdateTicketRuleParam
 *
 * @author zh.zhang <zh.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2021-09-08
 */
@Data
public class UpdateTicketRuleParam {
    @JsonProperty(value = "record_flag")
    private Integer recordFlag = 1;

    @JsonProperty(value = "createdID")
    private String createdId;

    @JsonProperty(value = "updatedID")
    private String updatedId;

    /**
     * 问卷id
     */
    private String surveyId;

    /**
     * 工单配置id
     */
    private String ticketConfigId;

    /**
     * 规则标题
     */
    private String title;

    /**
     * 同一问卷内，规则id唯一
     */
    private Integer gid;

    /**
     * 二次投放任务，工单完成或失败状态
     */
    private Integer operation;

    /**
     * 创建人
     */
    private String creator;

    /**
     * 版本号
     */
    private Integer version;

    /**
     * 规则类型
     *
     * @see com.bestcem.xm.ticket.enums.TicketRuleTypeEnum
     */
    @JsonProperty(value = "rtype")
    private Integer type;

    /**
     * 工单生成条件
     * 字段类型，需要确认具体字段
     */
    private Condition condition;

    private List<Target> targetList;

    /**
     * 生成条件列表
     */
    @JsonProperty(value = "conditionList")
    private List<Condition> conditionList;

    @Data
    public static class Condition {
        private Integer logic;

        private List<Filter> filters;

        private Integer ruleType;

        @Data
        public static class Filter {
            /**
             * 题目类型
             *
             * @see SurveyTitleTypeEnum
             */
            private Integer operation;

            private Integer category;

            private Value value;

            private List<SourceQ> sourceQ;

            @Data
            public static class Value {
                @JsonProperty(value = "naireOptions")
                private List<NaireOptions> naireOptions;

                private List<String> optionList;

                private Integer optionMatch;

                private List<String> wordList;

                private List<String> excludeList;

                private Options classify;

                private Boolean isOpen;

                /**
                 * 过期时间。单位秒s
                 */
                private Long expire;

                /**
                 * 前端传的参数中含有字段，数据库中没看到
                 */
                @JsonProperty(value = "again_d_t")
                private String againDt;

                /**
                 * 前端传的参数中含有字段，数据库中没看到
                 */
                private Integer type;
                @JsonProperty(value = "raw_project_id")
                private String rawProjectId;

                /**
                 * 前端传的参数中含有字段，数据库中没看到
                 */
                @JsonProperty(value = "deliver_project_id")
                private String deliverProjectId;

                /**
                 * 前端传的参数中含有字段，数据库中没看到
                 */
                @JsonProperty(value = "qtype")
                private String qType;


                private Integer sort;

                /**
                 * 时间类型的题目携带字段
                 */
                private List<String> time;

                /**
                 * 分数类型最小分数
                 */
                private Integer minScore;

                /**
                 * 分数类型最大分数
                 */
                private Integer maxScore;

                /**
                 * 过期天数
                 */
                private Integer days;

                /**
                 * 分数类型最小分数边界
                 */
                private Boolean leftOpen;

                /**
                 * 分数类型最大分数边界
                 */
                private Boolean rightOpen;

                /**
                 * 日期类型的题目携带字段
                 */
                private List<String> date;

                @Data
                public static class NaireOptions {
                    private List<Options> options;

                    private String type;

                    private Integer gid;

                    private Integer oid;

                    private String title;

                    private SourceQ.Item.OpenAttrs openAttrs;

                    private Boolean isOpen;

                    private Integer seq;
                }
            }

            /**
             * Options
             */
            @Data
            public static class Options {
                private Integer gid;

                private String type;

                private Integer seq;

                private Integer oid;

                private String title;

                private Boolean disabled;

                @JsonProperty(value = "is_open")
                private Boolean open;

                @JsonProperty(value = "open_attrs")
                private SourceQ.Item.OpenAttrs openAttrs;
            }

            @Data
            public static class SourceQ {
                private String id;

                private String type;

                private String gid;

                private String cid;

                private String align;

                @JsonProperty(value = "options_random")
                private Boolean optionsRandom;

                private Boolean required;

                /**
                 * 问卷题目
                 */
                private String title;

                @JsonProperty(value = "qtype")
                private String qType;

                @JsonProperty(value = "custom_qtype")
                private String customQtype;

                @JsonProperty(value = "column_value")
                private Integer columnValue;

                @JsonProperty(value = "vote_setting")
                private Boolean voteSetting;

                private String answerStyle;

                @JsonProperty(value = "disp_code")
                private String dispCode;

                private Boolean fixed;

                private List<Item> items;

                private Boolean codeSelect;

                @JsonProperty(value = "jump_code")
                private String jumpCode;

                @JsonProperty(value = "score_range")
                private List<Integer> scoreRange;

                private String icon;

                @JsonProperty(value = "prompt_text")
                private PromptText promptText;


                @JsonProperty(value = "option_bind_list")
                private List<String> optionBindList;

                private Boolean optionsBindEffect;

                @JsonProperty(value = "option_group_list")
                private List<String> optionGroupList;

                private Boolean optionsGroupEffect;

                /**
                 * _index
                 */
                @JsonProperty(value = "_index")
                private String index;

                @JsonProperty(value = "options_group_random")
                private Boolean optionsGroupRandom;

                @JsonProperty(value = "group_align")
                private String groupAlign;

                private Integer seq;

                @JsonProperty(value = "default_q_timecost")
                private Integer defaultTimeCost;

                private List<Options> options;

                @Data
                public static class Item {

                    private String type;

                    private Integer gid;

                    private String title;

                    private Integer seq;

                    private Integer oid;

                    @JsonProperty(value = "is_open")
                    private String isOpen;

                    @JsonProperty(value = "disp_code")
                    private String dispCode;

                    @JsonProperty(value = "plaster_code")
                    private String plasterCode;

                    @JsonProperty(value = "open_attrs")
                    private OpenAttrs openAttrs;

                    @Data
                    public static class OpenAttrs {
                        private Boolean required;

                        private Integer type;

                        private List<String> range;

                        private String unique;
                    }

                }

                public static class PromptText {
                    @JsonProperty(value = "left_words")
                    private String leftWords;

                    @JsonProperty(value = "middle_words")
                    private String middleWords;

                    @JsonProperty(value = "right_words")
                    private String rightWords;
                }

            }

        }

    }

    @Data
    public static class Target {
        private String levelID;

        private String roleID;

        private List<RoleOption> roleOptions;

        @Data
        public static class RoleOption {
            private String id;
        }
    }

}
